package com.cl.utils;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.Period;
import java.util.Date;

@Component
public class TimeUtil {

    public String getTodayTime(){
        Date date = new Date();
        long time = date.getTime();
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(time);
        return format;
    }
    public String getTomorrowTime(){
        Date date = new Date(new Date().getTime() + (1000 * 60 * 60 * 24));
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
        String format = formatter.format(date);
        return format;
    }
    public String getYear(){
        Date date = new Date();
        long time = date.getTime();
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy");
        String year = formatter.format(time);
        return year;
    }
    public Period calculateTimeDifferenceByPeriod(int year, Month month, int dayOfMonth) {
        LocalDate today = LocalDate.now();
        LocalDate oldDate = LocalDate.of(year, month, dayOfMonth);
        Period p = Period.between(oldDate, today);
        return p;
    }

}
